<?php
class IndexController extends Zendvn_Controller_Action{
	
	//Mang tham so nhan duoc o moi Action
	protected $_arrParam;
	
	//Duong dan cua Controller
	protected $_currentController;
	
	//Duong dan cua Action chinh
	protected $_actionMain;
	
	//Thong so phan trang
	
	
	public function init(){
		//Mang tham so nhan duoc o moi Action
		$this->_arrParam = $this->_request->getParams();
	
		//Truyen ra view
		$this->view->arrParam = $this->_arrParam;
		$this->view->currentController = $this->_currentController;
		$this->view->actionMain = $this->_actionMain;
		$this->view->active =$this->_arrParam['controller'];
		$template_path = TEMPLATE_PATH . "/font";
		$this->loadTemplate($template_path,'template.ini','template');
		$dataBanner = new Font_Model_Banner();
		$banner=$dataBanner->getBanner();
		$this->view->banner=$banner;
	
		}

	public function indexAction(){
		$dataBase = new Font_Model_Pages();
		if(isset($this->_arrParam['id'])){
			$pages=$dataBase->getAll($this->_arrParam['id']);
			if($this->_arrParam['id']=="1"){
				$this->view->headTitle("Chương Trình Đào Tạo",true);
			}else if($this->_arrParam['id']=="2"){
				$this->view->headTitle("Lịch Khai Giảng",true);
			}
			else{
				$this->view->headTitle("Mẫu Phôi Bằng",true);
			}
			
			
		}else{
			$pages=$dataBase->getAll(1);
			$this->view->headTitle("RDC",true);
		}
		
		$pa = Zend_Paginator::factory($pages);
		$pa->setItemCountPerPage(4);// xet so hang tren mọt trang
		$pa->setPageRange(5);
		$current = $this->_request->getParam('page');
		$pa->setCurrentPageNumber($current);
		// phan trang cache du lieu
		$fO = array("lifetime"=>3600, "automatic_serialization"=>true);
		$bO = array("cache_dir"=> APPLICATION_PATH.'/../public/tmp');
		$cache = Zend_Cache::factory('Core', 'File', $fO,$bO);
		Zend_Paginator::setCache($cache);
		$this->view->pages=$pa;

	}
	public function  viewAction(){
		$dataBase = new Font_Model_Pages();
		$page = $dataBase->getPage($this->_arrParam);
		if($page == null){
			$this->_redirect ( "font/index/error" );
		}
		$this->view->page =$page;
		$this->view->Title = $page['title'];
		$this->view->headTitle($this->view->Title,true);
		$this->view->headMeta()->appendName('description', $page['description']);
		$this->view->headMeta()->appendName('description', $page['description']);
	}
	public  function registerAction(){
		
	
	}
	public function errorAction(){
		
	}

}